package com.automation.monkeytalk;


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;

import org.junit.Test;

public class ExecuteShellScript_CompileAndInstallApp {

  @Test
  public void executeShellScript() throws Exception {

    System.out.println("Starting....");
    String line;
    ProcessBuilder builder = new ProcessBuilder("/bin/bash", "./shell/copy_json_to_data_dir.sh");
    builder.redirectErrorStream(true);
    Process process = builder.start();
    OutputStream stdin = process.getOutputStream();
    InputStream stderr = process.getErrorStream();
    InputStream stdout = process.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(stdout));
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(stdin));


    line = reader.readLine();
    while (line != null && !line.trim().equals("--EOF--")) {

      System.out.println("Stdout: " + line);
      line = reader.readLine();
      if (line == null) {
        break;
      }
    }
    System.out.println("Ending....");


  }



}
